;;; init-theme.el --- Emacs theme and ui configuration -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:

(setq ctrlwei/fonts '(("Comic Code" 16 medium "HarmonyOS Sans SC" 1.0 normal)
                      ("Cascadia Code" 16 normal "HarmonyOS Sans SC" 1.0 normal)
                      ("MonacoB" 15 normal "HarmonyOS Sans SC" 1.1 normal)
                      ("Consolas" 17 normal "HarmonyOS Sans SC" 1.0 normal)
                      ("Iosevka Fixed SS12" 17 normal "Sarasa Mono SC" 1.0 normal)))

(defun ctrlwei/setting-fonts (&optional use-default)
  "Setting fonts according the select list from `ctrlwei/fonts'.
if USE-DEFAULT is no-nil, then use first element of `ctrlwei/fonts'."
  (interactive)
  (let* ((default-fonts (caar ctrlwei/fonts))
         (fonts (if use-default
                    default-fonts
                  (completing-read
                   (format "Select fonts (default use %s): " default-fonts)
                   ctrlwei/fonts
                   nil t nil nil
                   default-fonts)))
         (fonts-info (assoc fonts ctrlwei/fonts))
         (EN-font (car fonts-info))
         (EN-font-size (nth 1 fonts-info))
         (EN-font-weight (nth 2 fonts-info))
         (CN-font (nth 3 fonts-info))
         (CN-font-rescale (nth 4 fonts-info))
         (CN-font-weight (nth 5 fonts-info)))
    (set-face-attribute
     'default nil
     :font (font-spec :name  EN-font
                      :weight EN-font-weight
                      :slant 'normal
                      :size EN-font-size))
    (dolist (charset '(kana han symbol cjk-misc bopomofo))
      (set-fontset-font t charset (font-spec :family CN-font :weight CN-font-weight)))
    (setq face-font-rescale-alist `((,CN-font . ,CN-font-rescale)))
    (set-face-attribute 'fixed-pitch nil :family EN-font)
    (set-face-attribute 'fixed-pitch-serif nil :family EN-font)
    (set-face-attribute 'variable-pitch nil :family EN-font)))

(ctrlwei/setting-fonts t)



(defun toggle-undecorated ()
  "Toggle decorations of Emacs window."
  (interactive)
  (if (frame-parameter nil 'undecorated)
      (set-frame-parameter nil 'undecorated nil)
    (set-frame-parameter nil 'undecorated t)))



;; Set emacs theme
(require 'spacemacs-dark-theme)
(setq spacemacs-theme-comment-italic t)
(load-theme 'spacemacs-dark 1)

;; for modus-themes
(setq modus-themes-slanted-constructs t
      modus-themes-bold-constructs nil
      modus-themes-no-mixed-fonts t
      modus-themes-mode-line '(borderless accented)
      modus-themes-completions '((popup accented))
      modus-themes-syntax '(green-strings)
      modus-themes-region '(no-extend accented)
      modus-themes-org-blocks 'gray-background
      modus-themes-paren-match '(intense underline)
      )

(defun my-modus-themes-faces ()
  (modus-themes-with-colors
    (custom-set-faces
     `(fringe ((,c :background ,bg-main)))))
  (custom-set-faces
   '(bold ((t :weight normal)))))
(add-hook 'modus-themes-after-load-theme-hook #'my-modus-themes-faces)

(defun load-modus-themes ()
  (interactive)
  (require-theme 'modus-themes t)
  (if current-prefix-arg
      (let ((modus-themes-to-toggle '(modus-vivendi modus-operandi)))
        (modus-themes-toggle))
    (modus-themes-toggle)))



;; Hide mode line, get from http://bzg.fr/emacs-hide-mode-line.html
(defvar-local hidden-mode-line-mode nil)
(defvar-local hide-mode-line nil)
(define-minor-mode hidden-mode-line-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global t
  :variable hidden-mode-line-mode
  :group 'editing-basics
  (if hidden-mode-line-mode
      (setq hide-mode-line mode-line-format
            mode-line-format nil)
    (setq mode-line-format hide-mode-line
          hide-mode-line nil))
  (force-mode-line-update)
  ;; Apparently force-mode-line-update is not always enough to
  ;; redisplay the mode-line
  (redraw-display)
  (when (and (called-interactively-p 'interactive)
             hidden-mode-line-mode)
    (run-with-idle-timer
     0 nil 'message
     (concat "Hidden Mode Line Mode enabled.  "
             "Use M-x hidden-mode-line-mode to make the mode-line appear."))))

;; display time in mode line
(with-eval-after-load 'time
  (setq display-time-format "%H:%M")
  (setq display-time-string-forms
        '((propertize
           (format-time-string display-time-format now)
           'face 'font-lock-constant-face
           'help-echo (format-time-string "%y/%m/%d|%V-%u %H:%M %z" now))))
  (setq display-time-default-load-average nil))
(display-time-mode 1)

;; (setq mode-line-compact t)
(setq mode-line-collapse-minor-modes '(not lsp-mode))
(setq-default mode-line-format (list " "
                                     'mode-line-mule-info
                                     'mode-line-modified
                                     'mode-line-remote
                                     'mode-line-window-dedicated
                                     " "
                                     '(:eval (propertize "%b"
                                                         'face 'font-lock-keyword-face
                                                         'help-echo (buffer-file-name)))
                                     " "
                                     (propertize "%l." 'face 'font-lock-type-face)
                                     `(3 (:propertize "%C " face font-lock-type-face display (min-width (3.0))))

                                     (propertize "%I" 'face 'font-lock-constant-face)
                                     " "
                                     `(:propertize ("" (-3 "%o")) face font-lock-constant-face)
                                     " "
                                     `(:propertize ("" mode-name)
                                                   help-echo "Major mode\n\
mouse-1: Display major mode menu\n\
mouse-2: Show help for major mode\n\
mouse-3: Toggle minor modes"
                                                   face font-lock-string-face
                                                   mouse-face mode-line-highlight
                                                   local-map ,mode-line-major-mode-keymap)

                                     ;; 'mode-line-minor-modes
                                     `(:propertize ("" mode-line-process) face font-lock-string-face)
                                     'mode-line-minor-modes
                                     '(vc-mode vc-mode)
                                     '(project-mode-line project-mode-line-format)
                                     " "
                                     'mode-line-misc-info
                                     " "
                                     (propertize "CZ" 'face 'font-lock-keyword-face
                                                 'help-echo "这个世界有很多黑暗的地方，我们要尽量让自己生活在光明里。")))


;; Set continuation indicators only show right bitmap
(setf (cdr (assq 'continuation fringe-indicator-alist))
      '(nil right-curly-arrow))

(provide 'init-theme)
;;; init-theme.el ends here
